# page/page_personal_finance.py
import time
from base.base import Base
from selenium.webdriver.common.by import By
from loc.personal_finance_page_locators import PersonalFinancePageLocators

class PagePersonalFinance(Base):
    def purchase_product(self, menu_index, button_index, password):
        """
        购买理财产品的通用方法
        :param menu_index: 左侧子菜单的索引 (1, 2, 3...)
        :param button_index: 表格中购买按钮所在列的索引
        :param password: 支付密码
        """
        # 动态定位子菜单并点击
        sub_menu_locator = (By.XPATH, f'/html/body/div/div/aside/div[2]/nav/ul/li[2]/ul/li[{menu_index}]/a')
        self.click(sub_menu_locator)
        time.sleep(1)

        # 动态定位购买按钮并点击
        buy_button_locator = (By.XPATH, f'/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[{button_index}]/button')
        self.click(buy_button_locator)
        time.sleep(1)

        # 输入密码并确认
        self.input_text(PersonalFinancePageLocators.PURCHASE_PASSWORD_INPUT, password)
        time.sleep(1)
        self.click(PersonalFinancePageLocators.CONFIRM_PURCHASE_BUTTON)
        time.sleep(1)
        self.click(PersonalFinancePageLocators.PURCHASE_SUCCESS_CONFIRM_BUTTON)
        return self

    def get_purchase_success_message(self):
        """获取购买成功信息用于断言"""
        # return self.get_text(PersonalFinancePageLocators.PURCHASE_SUCCESS_MESSAGE)
        pass